const db = uniCloud.database();
const dbCmd = db.command;
const { chapterNameSplitStr } = require('../../config/index.js');
module.exports = async function(options = {}) {
	const { characterId, uid, chapter } = options;
	const token = this.getUniIdToken();
	if (!token || !characterId || !chapter || !uid) {
		throw new Error('非法操作');
	}
	await Promise.all([
		db.collection('a-dz-chapter-list-custom').where({ characterId, uid, chapter }).remove(),
		db.collection('a-dz-category-list-custom').where({ characterId, uid, chapter }).remove(),
		db.collection('a-dz-course-list-custom').where({ characterId, uid, chapter }).remove(),
		db.collection('a-dz-complete-list-custom').where({ chapter }).remove(),
		db.collection('a-dz-complete-stats-list').where({ chapter }).remove(),
		db.collection('a-dz-group-list').where({ characterId }).update({
			chapters_custom: dbCmd.pullAll([chapter])
		}),
		db.collection('uni-id-users').where({
			chapters_custom: { $exists: true, $ne: [], $type: "array" }
		}).update({ $pull: { chapters_custom: { $in: [chapter] } } }, { multi: true })
	])
	return {
		code: 0,
		msg: '删除成功'
	}
}